﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Elentok.Common.Wpf.Dialogs;
using System.Windows;

namespace Elentok.Common.Wpf.ViewModels.Dialogs
{
  /// <summary>
  /// Contains various dialogs-related extension methods
  /// </summary>
  public static class DialogsExtensions
  {
    /// <summary>
    /// Shows the about dialog
    /// </summary>
    /// <param name="viewModel">The view model.</param>
    public static void Show(this IAboutDialogViewModel viewModel)
    {
      var dialog = new AboutDialog(viewModel);
      dialog.Owner = Application.Current.MainWindow;
      dialog.ShowDialog();
    }


    /// <summary>
    /// Open a resizable dialog the matches the given view model
    /// </summary>
    /// <param name="viewModel">The view model.</param>
    /// <returns></returns>
    public static bool? Show(this IDialogViewModel viewModel)
    {
      return viewModel.Show(true);
    }

    /// <summary>
    /// Open a dialog the matches the given view model
    /// </summary>
    /// <param name="viewModel">The view model.</param>
    /// <param name="allowResize">if set to <c>true</c> allow resizing the dialog.</param>
    /// <returns></returns>
    public static bool? Show(this IDialogViewModel viewModel, bool allowResize)
    {
      var dialog = new Dialog(viewModel);

      if (Application.Current != null && Application.Current.MainWindow != null)
        dialog.Owner = Application.Current.MainWindow;

      if (!allowResize)
        dialog.ResizeMode = ResizeMode.NoResize;

      return dialog.ShowDialog();
    }

  }
}
